#include "CProduction_Statement.h"
#include "Statement.h"
#include "Statement_List.h"
#include "Statement_Print.h"
#include "Statement_Empty.h"
#include "Statement_If.h"

CTokenPtr CProduction_Statement_Complete::Reduce( CProductionArgPtr pArgs )
{
	return pArgs->getArg<CStatement>(0);
}

CTokenPtr CProduction_Statement_Copy::Reduce( CProductionArgPtr pArgs )
{
	pArgs->getArg<CStatement>(0)->eval();
    return pArgs->getArg<CStatement>(0);
}

CTokenPtr CProduction_Statement_Empty::Reduce( CProductionArgPtr pArgs )
{
	return CTokenFactory::createToken<CStatement_Empty>();
}

CTokenPtr CProduction_Statement_Print::Reduce( CProductionArgPtr pArgs )
{
    CExpressionPtr pExp = pArgs->getArg<CExpression>(1);

    CStatement_PrintPtr pResult = CTokenFactory::createToken<CStatement_Print>();

    pResult->m_pExp = pExp;

	pResult->eval();

    return pResult;
}

CTokenPtr CProduction_Statement_List::Reduce( CProductionArgPtr pArgs )
{
	CStatementPtr pState = pArgs->getArg<CStatement>(0);

	CStatementListPtr pResult = CTokenFactory::createToken<CStatementList>();

	pResult->AddStatement(pState);

	return pResult;
}

CTokenPtr CProduction_Statement_List_Append::Reduce( CProductionArgPtr pArgs )
{
	CStatementListPtr pResult = pArgs->getArg<CStatementList>(0);

	CStatementPtr pState = pArgs->getArg<CStatement>(1);

	pResult->AddStatement(pState);

	return pResult;
}


CTokenPtr CProduction_Statement_Block::Reduce( CProductionArgPtr pArgs )
{
	return pArgs->getArg<CStatement>(1);
}


